<template>
    <view style="background-color: #ec633e; width: 750rpx; height: 600rpx"></view>
    <z-paging
        refresher-theme-style="white"
        ref="paging"
        v-model="newsList"
        :auto="true"
        @query="getNewsList"
        @scroll="onPageScroll"
    >
        <view style="background-color: #f8f8f8">
            <home-head
                ref="head"
                :province="province"
                :userInfo="userInfo"
                :gaokaoDays="gaokaoDays"
                :backgroundColor="opacityNum"
                :fontColor="fontColor"
                :volunteerinfo="volunteerinfo"
                :schoolNumber="schoolNumber"
                :zy_type="zy_type"
                :count="count"
                :newMessage="newMessage"
                :changeisgaokao="isgaokao"
                @changeGaokaoShow="handleShowGk"
            ></home-head>
            <home-center
                class="home-center"
                :class="!userInfo ? 'home-center-1' : ''"
                @onClickCenterItem="onClickCenterItem"
            ></home-center>
            <view class="view-banner">
                <image
                    class="banner-image"
                    src="https://mcdn.chatgk.com/xcx/static/images/home/home_banner_7.png"
                    mode="aspectFit"
                    @tap="onClickBannerItem(3)"
                ></image>
                <image
                    class="banner-image"
                    :src="
                        xcxName != '报考管家'
                            ? 'https://mcdn.chatgk.com/xcx/static/images/home/home_banner_4.png'
                            : 'https://mcdn.chatgk.com/xcx/static/images/home/home_banner_4_bkgj.png'
                    "
                    mode="aspectFit"
                    @tap="onClickBannerItem(4)"
                ></image>
                <image
                    class="banner-image"
                    src="https://mcdn.chatgk.com/xcx/static/images/home/home_banner_6.png"
                    mode="aspectFit"
                    @tap="onClickBannerItem(5)"
                ></image>
            </view>

            <home-hot :hotNews="hotNews"></home-hot>

            <home-daxue :collegeList="collegeList" :lunbonews="lunbonews" />
        </view>

        <view class="home-bottom-tab">
            <text class="home-bottom-tab-item-title home-bottom-tab-item-title-active">最新资讯</text>
        </view>
        <view
            class="home-bottom-page-item"
            v-for="(item, index) in newsList"
            :key="item.nid"
            @tap="onClickHotNews(item)"
        >
            <view class="home-bottom-page-item-sub">
                <view :style="'width:' + (item.image_url && item.image_url.length > 0 ? '430rpx;' : '620rpx')">
                    <text class="home-bottom-page-title">{{ item.title }}</text>
                    <view style="display: flex; flex-direction: row; align-items: center; margin-top: 20rpx">
                        <text class="home-bottom-page-time" space="nbsp">
                            {{ item.source + '  ' + filtrationed(item.update_time) }}
                        </text>
                        <image
                            style="width: 30rpx; height: 20rpx; margin: 0 5rpx 0 20rpx"
                            src="https://mcdn.chatgk.com/xcx/static/images/public/eyes_n.png"
                            mode="aspectFit"
                        ></image>
                        <text class="home-bottom-page-time">{{ formatReadNum(item.view_total) }}</text>
                    </view>
                </view>
                <image
                    v-if="item.image_url && item.image_url.length > 0"
                    class="home-bottom-page-image"
                    :src="item.image_url"
                ></image>
            </view>
        </view>
    </z-paging>

    <isgkb @colse_gkb="colse_gkb" v-if="gaokaoshow"></isgkb>

    <loading v-show="loadshow"></loading>
    <!-- <progress_bar v-if="ishowjdt" :jdtNumber="jdtNumber" style="	width: 750rpx;
		height: 3000rpx;position: fixed;top: 0;z-index: 99999;">
	</progress_bar> -->

    <!-- 体验卡 -->
    <view class="popup-center" v-if="opens" @touchmove.stop.prevent="stopscroll">
        <view class="popup-center-box">
            <view class="p-c-b-top">
                <image class="tuijian" src="https://mcdn.chatgk.com/xcx/static/images/home/tuijian.png" alt=""></image>
                <image
                    class="close"
                    style="width: 80rpx; height: 80rpx"
                    src="https://mcdn.chatgk.com/xcx/static/images/chancePageImg/gb.png"
                    mode=""
                    @tap.stop="endVipTrialPopup"
                ></image>
                <view class="top-title">会员体验卡</view>
                <view class="maney">
                    <!-- <h1>9.9</h1> -->
                    <text
                        style="
                            font-family: Arial, Helvetica, sans-serif;
                            font-size: 90rpx;
                            font-weight: 600;
                            margin-top: 5rpx;
                        "
                    >
                        9.9
                    </text>
                    <image class="yuan" src="https://mcdn.chatgk.com/xcx/static/images/home/yuan.png" alt=""></image>
                </view>
                <view class="top-content">
                    <view>1.使用会员体验卡可享受升学卡会员的所有特权</view>
                    <view style="color: #999999; font-size: 26rpx">（1.志愿填报 2.新高考选科 3.学业测评4.提前批）</view>
                </view>
                <view class="p-c-b-top-button" @tap="onClickOpenTrialVip">立即开通</view>
                <view class="validity">体验卡的有效期至6月20日</view>
            </view>
        </view>
    </view>

    <!-- 志愿卡 -->
    <view class="popup-center" v-if="openVipCoupon" @touchmove.stop.prevent="stopscroll">
        <view class="popup-center-box">
            <view class="p-c-b-top">
                <image class="tuijian" src="https://mcdn.chatgk.com/xcx/static/images/home/tuijian.png" alt=""></image>
                <image
                    class="close"
                    style="width: 80rpx; height: 80rpx"
                    src="https://mcdn.chatgk.com/xcx/static/images/chancePageImg/gb.png"
                    mode=""
                    @tap.stop="endVipTrialPopup"
                ></image>
                <view class="top-title">志愿填报VIP志愿卡</view>
                <view class="maney">
                    <!-- <h1>9.9</h1> -->
                    <text
                        style="
                            font-family: Arial, Helvetica, sans-serif;
                            font-size: 90rpx;
                            font-weight: 600;
                            margin-top: 5rpx;
                        "
                    >
                        98
                    </text>
                    <image class="yuan" src="https://mcdn.chatgk.com/xcx/static/images/home/yuan.png" alt=""></image>
                </view>
                <view class="top-content">
                    <view>使用志愿填报AI数据卡享受以下所有特权</view>
                    <view style="color: #999999; font-size: 26rpx">
                        (1.志愿填报 2.专业定位测评 3.提前批 4.查录取率)
                    </view>
                </view>
                <view class="p-c-b-top-button" @tap="onClickOpenVolunteerVip">立即开通填报志愿</view>
                <!-- <view class="validity">体验卡的有效期至6月20日</view> -->
            </view>
        </view>
    </view>

    <!-- 高考版 -->
    <view class="popup-center-isGKB" v-if="openShow" @touchmove.stop.prevent="stopscroll">
        <view class="popup-center-box-isGKB">
            <view class="top-title-isGKB">
                <view class="center-top">2024</view>
                <view class="center-top">高考版已开启</view>
            </view>
            <view class="countent">
                <view class="txt">2024专业定位测评系统</view>
                <view class="txt">2024招生计划同步更新</view>
                <view class="txt">2024个性化多种模拟填报模式</view>
                <view class="txt">2023专业录取数据 规避落榜风险</view>
            </view>
            <view class="button">
                <text class="txt" @tap="isGKBcreatScore">创建高考成绩</text>
            </view>
            <view class="p-c-b-bottom-isGKB">
                <image
                    class="close-isGKB"
                    src="https://mcdn.chatgk.com/xcx/static/images/midTabBar/chacha@3x.png"
                    mode=""
                    @tap="endPopup"
                ></image>
            </view>
        </view>
    </view>
</template>

<script>
// #ifdef APP-NVUE
const dom = weex.requireModule('dom');
// #endif

import homeHead from './home-head.vue';
import homeCenter from './home-center.vue';
import homeHot from './home-hot.vue';
import homeDaxue from './home-daxue.vue';
import homeBottomPage from './home-bottom-page.vue';
import userManager from '@/common/manager/user-manager.js';
import request from '@/common/request/api.js';
// import { timeago, formatReadNum } from '../../../common/manager/tool';
import tool from '../../../common/manager/tool';
import shareText from '@/common/manager/sharText.js';
// import md5 from '@/utils/md5.js'
import { mapState, mapActions, mapMutations } from 'vuex';
import { Iap, IapTransactionState } from '/common/request/iap.js';
import AppPay from '/common/request/appPay.js';
import xcxInfo from '@/common/manager/xcxInfo.js';

const appPay = new AppPay();
// import ZPMixin from '@/uni_modules/z-paging/components/z-paging/js/z-paging-mixin';
// 			ZPMixin.onPageScroll()
export default {
    components: {
        homeHead,
        homeCenter,
        homeHot,
        homeDaxue,
        homeBottomPage
        // ZPMixin
    },

    // mixins: [ZPMixin],
    data() {
        return {
            opens: false,
            openVipCoupon: false,
            openShow: false,
            loadshow: false,
            gaokaoshow: false,
            tabList: [
                {
                    title: '大家都在看',
                    pageid: 1
                },
                {
                    title: '最新资讯',
                    pageid: 2
                }
            ],
            // header高度
            headerHeight: 0,
            // 页面高度
            pageHeight: 0,
            currentIndex: 0,
            province: '北京',
            userInfo: {},
            gaokaoDays: 0,
            safeAreaBottom: 0,
            safeAreaTop: 0,
            hotNews: [],
            collegeList: [],
            newsList: [],
            page: 1,
            opacityNum: 'rgba(41, 73, 255,0)', //这是头部滚动时的透明度
            isPagingRefNotFound: 0,
            fontColor: false,
            allMajorDataList: [], //全部的专业数据列表
            allJobDataList: [],
            isgaokao: 0,
            volunteerinfo: 0,
            schoolNumber: 0,
            lunbonews: [],
            zy_type: 0,
            count: 0,
            newMessage: 0,
            diquObj: {},
            showgengxinData: false,
            // watchbanbengengxin: getApp().globalData.banbengengxin,
            jdtNumber: 0,
            ishowjdt: false, //进度条是否显示
            deviceInfo: {},

            isTyVipTime: 300,
            vipCoupon: false,
            showUpdateDate: 0,
            environment: '',
            iap: Iap,
            productList: [],
            productId: '',
            xcxName: xcxInfo.name
        };
    },
    // 分享
    onShareAppMessage: function (res) {
        if (res.from === 'button') {
            // 来自页面内转发按钮
            console.log(res.target);
        }
        return shareText;
    },
    onReady() {
        console.log('home:', getApp().globalData.banbengengxin);
        let pages = getCurrentPages();
        let currentPage = pages[pages.length - 1];
        let url = currentPage.route;
        console.log('this.openVipCoupon', this.openVipCoupon);
        console.log('this.openShow', this.openShow);
        console.log('this.opens', this.opens);
        let pid = Object.keys(this.diquObj).length < 1 ? 11 : this.diquObj.id;

        let body = {};
        if (!getApp().globalData.userInfo && pid != '') {
            body.pid = pid;
        }

        if (getApp().globalData.userInfo || Object.keys(body).length > 0) {
            this.$request.gkbInfo(body).then((res) => {
                if (
                    (res.data.isGKB == '1' && !getApp().globalData.userInfo.score) ||
                    getApp().globalData.userInfo?.score == 0
                ) {
                    if (this.opens || this.openVipCoupon) {
                        uni.hideTabBar();
                    } else {
                        this.openShow = true;
                        uni.hideTabBar();
                    }
                } else {
                    if (this.opens || this.openVipCoupon) {
                        uni.hideTabBar();
                    }
                }
                uni.setStorageSync('isGKB', res.data.isGKB);
                uni.setStorageSync('isGKB_graduate_time', res.data.graduate_time);
            });
        }
        // 获取配置信息
        this.$request.conifgData().then((res) => {
            const userInfo = getApp().globalData.userInfo;
            this.isTyVipTime = res.data.isTyVipTime;
            this.vipCoupon = res.data.vipCoupon;

            if (userInfo && !userInfo.isVIP && (userInfo.isTyVip || this.vipCoupon)) {
                this.isShowTyVip();
            }
        });

        // 获取设备信息
        this.environment = uni.getSystemInfoSync('systemInfo').osName;
    },
    async onLoad() {
        // 分享
        wx.showShareMenu({
            withShareTicket: true,
            menus: ['shareAppMessage', 'shareTimeline'] // 分享到朋友圈
        });
        this.pageHeight = uni.getSystemInfoSync().windowHeight;
        const store = uni.getSystemInfoSync();
        this.safeAreaBottom = store.safeAreaInsets.bottom;
        this.safeAreaTop = store.safeAreaInsets.top;

        if (!userManager.getProvinceInfo()) {
            if (Object.keys(this.diquObj).length < 1) {
                userManager.setProvinceInfo({
                    id: 11,
                    province: '北京'
                });
            } else {
                userManager.setProvinceInfo({
                    id: this.diquObj.id,
                    province: this.diquObj.name
                });
            }
        }
        const _this = this;
        setTimeout(() => {
            _this.getAllMajorDataList();
            _this.getAllJobDataList();
        }, 300);

        this.triggerFun();

        uni.removeStorageSync('schoolsearchSid');
        uni.removeStorageSync('schoolsearchData');
        uni.removeStorageSync('selFilterDatas');
        uni.removeStorageSync('selCollegeFilterData');
        uni.removeStorageSync('changeid');
        uni.removeStorageSync('selectData'); // 移除专业库的数据
        uni.removeStorageSync('searchDataARR');
        uni.removeStorageSync('selFilterDatas');
        uni.removeStorageSync('majorValueArr');
        uni.removeStorageSync('jobValueArr');
        uni.removeStorageSync('tablepaixu');
        this.getsqFlag();

        // 判断 有没有数据 没有数据请求接口
        const cacheData = uni.getStorageSync('cacheData') || false; // 从缓存中获取数据

        if (!cacheData) {
            const platform = uni.getSystemInfoSync().platform;
            if (platform == 'android') {
                this.getfacility(); //  加载获取设备基本信息
            }
        }
    },

    onShow() {
        let userInfo = getApp().globalData.userInfo;
        this.panduanisgaokao();
        this.gethasPushRedAPI();
        this.getAllMessage();
        uni.removeStorageSync('selectData'); // 移除专业库的数据

        if (getApp().globalData.userInfo) {
            request.provinceInfo().then((res) => {
                uni.setStorageSync('provinceInfo', res.data);
                res.data.forEach((item) => {
                    if (item.provinceName == getApp().globalData.userInfo.province) {
                        this.zy_type = Number(item.zy_type);
                    }
                });
            });
            this.zyList();
            this.handleIsPageData();
            this.score_gkb = getApp().globalData.userInfo.score_gkb;
        }
        const newUserInfo = getApp().globalData.userInfo || '';
        const oldUserInfo = this.userInfo || {};

        if (newUserInfo && oldUserInfo.grade != newUserInfo.grade) {
            this.getHowManyDays();
        }

        this.userInfo = newUserInfo;
        this.getProvinceInfo();
    },
    onUnload() {
        // 页面卸载时重置备份用户信息
        this.asyncSetCopyUserInfo({});
    },
    destroyed() {
        console.log('页面卸载了');
    },
    onHide() {
        // 不改变原来的逻辑与变量， 所以在页面隐藏时将用户信息保存在vuex中的备份变量中，以供后续比对用户信息使用
        this.asyncSetCopyUserInfo(getApp().globalData.userInfo);
    },
    computed: {
        ...mapState({
            copyUserInfo: (state) => state.user.copyUserInfo
        })
    },
    watch: {
        headerHeight: function (newVal) {
            this.setListSpecialEffects(newVal);
        }
    },
    methods: {
        ...mapActions(['asyncSetCopyUserInfo', 'asyncSetVolunteerInfo']),
        ...mapMutations(['SET_UPDATE_APP']),

        // 分享
        onShareAppMessage: function (res) {
            return {
                title: xcxInfo.name + ',你也来试试',
                path: 'pages/tabBar/home/home'
            };
        },

        endPopup() {
            this.openShow = false;
            uni.showTabBar();
        },
        stopscroll() {
            console.log('禁止滚动');
        },
        isGKBcreatScore() {
            uni.navigateTo({
                url: '/subpackages/subpackage1/pages/score/home-score'
            });
        },
        isShowTyVip() {
            // 显示体验卡弹窗
            const currentDate = new Date();
            const currentTime = currentDate.getTime();

            if (this.showUpdateDate != 0) {
                const time = Math.abs(currentTime - this.showUpdateDate) / 1000;

                if (time >= this.isTyVipTime) {
                    this.showUpdateDate = currentTime;
                    this.openVipTrialPopup();
                }
            } else {
                this.showUpdateDate = currentTime;
                this.openVipTrialPopup();
            }
        },
        openVipTrialPopup() {
            if (this.vipCoupon) {
                if (this.opens || this.openShow) {
                    uni.hideTabBar();
                } else {
                    this.openVipCoupon = true;
                    uni.hideTabBar();
                }
            } else {
                if (this.openVipCoupon || this.openShow) {
                    uni.hideTabBar();
                } else {
                    this.opens = true;
                    uni.hideTabBar();
                }
            }
        },
        endVipTrialPopup() {
            uni.showTabBar();
            this.opens = false;
            this.openVipCoupon = false;
        },

        getfacility() {
            // let that = this
            // // 获取设备基础信息
            // const deviceInfo = {
            // 	ts: Date.parse(new Date()) / 1000
            // } // 保存设备所有信息
            // //基础信息
            // const getDeviceInfo = uni.getDeviceInfo() // 获取设备基础信息
            // deviceInfo.deviceModel = getDeviceInfo.deviceModel // 设备型号
            // deviceInfo.brand = getDeviceInfo.brand // 厂家
            // deviceInfo.deviceType = getDeviceInfo.deviceType //设备类型
            // deviceInfo.system = getDeviceInfo.system // 系统版本
            // // 获取设备的mac地址
            // const net = plus.android.importClass('java.net.NetworkInterface');
            // const wlan0 = net.getByName('wlan0');
            // const macByte = wlan0.getHardwareAddress();
            // let macStr = '';
            // macByte.forEach(item => {
            // 	// .toString(16)数字以十六进制值显示
            // 	let temp = '';
            // 	if (item < 0) temp = (256 + item).toString(16);
            // 	else temp = item.toString(16);
            // 	if (temp.length == 1) temp = `0${temp}`;
            // 	macStr += temp;
            // });
            // let mac = macStr.toUpperCase();
            // for (let i = 2; i < mac.length; i += 3) mac = mac.slice(0, i) + ':' + mac.slice(i);
            // deviceInfo.mac = mac; // 保存设备的mac 地址
            // deviceInfo.imei = plus.device.imei // 设备imei
            // // 获取设备的ip地址
            // var MainActivity = plus.android.runtimeMainActivity();
            // var Context = plus.android.importClass('android.content.Context');
            // plus.android.importClass("android.net.wifi.WifiManager")
            // var wifiManager = MainActivity.getSystemService(Context.WIFI_SERVICE)
            // //获取dhcp ip
            // var intent = plus.android.newObject("android.net.DhcpInfo");
            // var info = wifiManager.getDhcpInfo();
            // var ipAddress = plus.android.getAttribute(info, "serverAddress");
            // var ip = ((ipAddress & 0xff) + "." + (ipAddress >> 8 & 0xff) + "." + (ipAddress >> 16 & 0xff) + "." + (
            // 	ipAddress >> 24 & 0xff))
            // deviceInfo.ip = ip // 保存设备的ip地址
            // uni.getSystemInfo({
            // 	// 获取当前设备的具体信息
            // 	success: sysinfo => {
            // 		that.deviceInfo.oaid = sysinfo.oaid
            // 	}
            // });
            // // 方法一：
            // let mainActivity = plus.android.runtimeMainActivity();
            // let Settings = plus.android.importClass("android.provider.Settings");
            // let uuid = Settings.Secure.getString(mainActivity.getContentResolver(), Settings.Secure.ANDROID_ID);
            // deviceInfo.android_id = uuid
            // const device =
            // 	`android_id=${deviceInfo.android_id}&oaid=${that.deviceInfo.oaid}&deviceModel=${deviceInfo.deviceModel}&brand=${deviceInfo.brand}&deviceType=${deviceInfo.deviceType}&system=${deviceInfo.system}&mac=${deviceInfo.mac}&imei=${deviceInfo.imei}&ip=${ip}&ts=${deviceInfo.ts}/submit`
            // // 使用md5加密数据信息
            // const deviceMd5 = md5.hex_md5(device)
            // const saveDevice = {
            // 	...deviceInfo,
            // 	...that.deviceInfo,
            // 	signature: deviceMd5,
            // }
            // this.$request.collect(saveDevice).then(res => {
            // 	uni.setStorageSync('cacheData', true); // 存储数据到缓存
            // })
        },

        /**
         * @description: 判断是否需要请求页面数据更新
         * @return
         */
        handleIsPageData() {
            // 这是简单比对， 复杂情况可使用迭代比对
            if (JSON.stringify(this.copyUserInfo) === JSON.stringify(getApp().globalData.userInfo)) {
                console.log('用户信息比对一致， 不发送请求');
            } else {
                console.log('用户信息比对不一致， 发送请求');
                this.getshcoolnum();
            }
        },

        /**
         * @description: 获取省份信息
         * @return
         */
        getProvinceInfo() {
            if (this.userInfo?.province) {
                this.province = this.userInfo.province;
                return;
            }

            const provinceInfo = userManager.getProvinceInfo();

            // ?. 可选链操作符
            // this.province = provinceInfo?.province || '北京'
            this.province = provinceInfo?.provinceName || '北京';
        },
        /**
         * @param {Boolean} show 是否显示高考版提示弹窗
         */
        handleShowGk(show) {
            this.gaokaoshow = show;
        },
        panduanisgaokao() {
            // request.isGKB().then((res) => {
            let pid = '';

            if (Object.keys(this.diquObj).length < 1) {
                pid = 11;
            } else {
                pid = this.diquObj.id;
            }

            let body = {};
            if (!getApp().globalData.userInfo && pid != '') {
                body.pid = pid;
            }

            if (getApp().globalData.userInfo || Object.keys(body).length > 0) {
                request.gkbInfo(body).then((res) => {
                    this.isgaokao = res.data.isGKB;
                    uni.setStorageSync('isGKB', this.isgaokao);
                    uni.setStorageSync('isGKB_graduate_time', res.data.graduate_time);
                    if (
                        this.isgaokao == 1 &&
                        this.userInfo.score_gkb == 0 &&
                        this.userInfo.graduate_time == res.data.graduate_time
                    ) {
                        uni.navigateTo({
                            url: '/subpackages/subpackage1/pages/score/home-score'
                        });
                    }
                });
            }
        },

        showgengxin() {
            uni.showTabBar();
            this.showgengxinData = false;
            this.SET_UPDATE_APP(false);
        },
        upDownload() {
            //这是传递回调  使用Uni.emit
            let that = this;
            // this.showgengxinData = false
            // this.SET_UPDATE_APP(false)
            this.ishowjdt = true;
            uni.hideTabBar();
            uni.$on('jdt_number', function (num) {
                that.jdtNumber = num;
            });
            uni.$emit('banbengengxingFUN');
        },
        getsqFlag() {
            let a = uni.getStorageSync('shenqingchuqun') || '1';
            getApp().globalData.shequflag = a;
        },
        triggerFun() {
            let that = this;
            uni.$once('changeHomeProvince', function (e) {
                that.province = e.provinceName;
                that.diquObj = e;
                userManager.setProvinceInfo({
                    id: e.id,
                    province: e.provinceName
                });
            });
        },
        getAllMessage() {
            const id = uni.getStorageSync('zhinengkefuMessage') || '';
            if (id > 0) {
                this.getNewMessage(id);
            }
        },

        getNewMessage(id) {
            let data = {
                id: id,
                hasNew: 1
            };
            request.customerQuestionAskGetAPI(data).then((res) => {
                if (res.data.count > 0) {
                    this.newMessage = 1;
                } else {
                    this.newMessage = 0;
                }
            });
        },
        gethasPushRedAPI() {
            request.hasPushRed().then((res) => {
                this.count = res.data.count;
            });
        },
        getshcoolnum() {
            const data = {};
            data['pid'] = getApp().globalData.userInfo.pid;
            data['less'] = '1';

            // this.loadshow = true

            request
                .batchlineInfo(data)
                .then((res) => {
                    let obj = {
                        onlySummary: 1 // 简洁响应
                    };
                    res.data.batches.forEach((item) => {
                        if (item.batch == getApp().globalData.userInfo.batch) {
                            obj.batchLine = item.score;
                        }
                    });
                    obj.batch = getApp().globalData?.userInfo?.batch;
                    request
                        .schoolEnrollChance(obj)
                        .then((res) => {
                            if (
                                this.schoolNumber !=
                                res.data.summary.chance_lv_1 +
                                    res.data.summary.chance_lv_2 +
                                    res.data.summary.chance_lv_3
                            ) {
                                this.schoolNumber =
                                    res.data.summary.chance_lv_1 +
                                    res.data.summary.chance_lv_2 +
                                    res.data.summary.chance_lv_3;
                            }

                            this.loadshow = false;
                        })
                        .catch((res) => {
                            this.loadshow = false;
                            uni.hideToast();
                        });
                })
                .catch((err) => {
                    this.loadshow = false;
                });
        },
        zyList() {
            request
                .zyList({
                    page: 0,
                    pageSize: 0
                })
                .then((res) => {
                    // let numa = 0
                    // res.data.forEach(item => {
                    // 	if (item.status == 1) {
                    // 		numa++
                    // 	}

                    // })
                    // this.asyncSetVolunteerInfo({}) //清空数据信息
                    this.asyncSetVolunteerInfo(this.zy_type == 3 ? {} : []); //清空数据信息
                    uni.setStorageSync('lisi', ''); // 重置历史数据
                    this.volunteerinfo = res.data.count || 0;
                });
        },
        colse_gkb() {
            this.gaokaoshow = false;
            uni.showTabBar();
        },
        getAllMajorDataList() {
            request.searchAllMajor().then((res) => {
                uni.setStorageSync('allMajorDataList', res.data);
                // this.allMajorDataList = res.data
            });
        },
        getAllJobDataList() {
            request.allCareer().then((res) => {
                uni.setStorageSync('allJobDataList', res.data);
                // this.allJobDataList = res.data
            });
        },
        filtrationed(res) {
            return tool.timeago(res);
        },
        formatReadNum(num) {
            return tool.formatReadNum(num);
        },
        refreshData() {
            this.getHowManyDays();
            this.getHotSchool();
            this.getHotNews();
        },
        // 获取高考倒计时
        getHowManyDays() {
            request.howManyDays().then((res) => {
                this.gaokaoDays = res.data.days;
            });
        },
        getHotNews() {
            request
                .hotNews({
                    hot: 1
                })
                .then((res) => {
                    this.hotNews = res.data;
                });
        },
        //获取轮播图数据
        getlunbo() {
            request
                .hotNews({
                    banner: 1
                })
                .then((res) => {
                    this.lunbonews = res.data;
                });
        },
        // 获取热门学校
        getHotSchool() {
            request.homeHotSchool().then((res) => {
                this.collegeList = res.data;
            });
        },
        // 获取最新咨询
        getNewsList(page, pageSize) {
            let windo = uni.getWindowInfo();

            if (page == 1) {
                this.getHowManyDays();
                this.getHotNews();
                this.getlunbo();
                this.getHotSchool();
            }

            request
                .hotNews({
                    page: page,
                    pageSize: pageSize
                })
                .then((res) => {
                    this.$refs.paging.complete(res.data);
                    // this.newsList.push(res.data)
                })
                .catch((err) => {
                    this.$refs.paging.complete(false);
                });
        },
        // 点击最新新闻
        onClickHotNews(item) {
            uni.navigateTo({
                url:
                    '/subpackages/subpackage1/pages/searchcollege/collegeDetails/news-details?data=' +
                    encodeURIComponent(JSON.stringify(item)) +
                    '&num=2'
            });
            // id传值
            // uni.navigateTo({
            // 	url: '/subpackages/subpackage1/pages/searchcollege/collegeDetails/news-details?id=' + item.id + '&num=2'
            // })
        },
        onClickCenterItem(index) {
            console.log(uni.getStorageSync('is_visitor'), 'is_visitor');
            if (uni.getStorageSync('is_visitor') == 1) {
                uni.navigateTo({
                    url: '/pages/login/login-home'
                });
            } else {
                index = Number(index);
                let goPageUrl = undefined;
                let dict = {
                    0: '/subpackages/subpackage1/pages/searchcollege/home-searchcollege',
                    1: '/subpackages/subpackage1/pages/searchmajor/seemajor',
                    2: '/subpackages/subpackage1/pages/seejob/seejobnew',
                    3: '/subpackages/subpackage1/pages/zhinengxuanke/zhinengxuanke',
                    4: '/subpackages/subpackage1/pages/tiqianpi/tiqianpi',
                    5: '/subpackages/subpackage1/pages/batchline/batchline',
                    6: '/subpackages/subpackage1/pages/scoreline/scoreline',
                    7: '/subpackages/subpackage1/pages/rankquery/rankquery',
                    8: '/subpackages/subpackage1/pages/chancePage/chancePage',
                    9: '/subpackages/subpackage1/pages/sameDistributionDirection/sameDistributionDirection'
                };

                if ([0, 1, 2, 6, 7].includes(index)) {
                    goPageUrl = dict[index];
                }

                if (index == 4) {
                    // 登录
                    if (!userManager.isLogin()) {
                        return;
                    }
                    // vip
                    const userInfo = getApp().globalData.userInfo;
                    // 省份
                    if (!userInfo.pid) {
                        uni.navigateTo({
                            url: '/subpackages/subpackage2/pages/login/perfect-info'
                        });
                        return;
                    }
                    goPageUrl = '/subpackages/subpackage1/pages/tiqianpi/tiqianpi';
                } else if (index == 3) {
                    // 登录
                    if (!userManager.isLogin()) {
                        return;
                    }
                    // goPageUrl = '/subpackages/subpackage1/pages/zhinengxuanke/zhinengxuanke';
                } else if (index == 5) {
                    if (!userManager.isLogin()) {
                        return;
                    }
                    goPageUrl = '/subpackages/subpackage1/pages/batchline/batchline';
                } else if (index == 9) {
                    // 招生计划
                    // goPageUrl = '/subpackages/subpackage1/pages/enrollmentplan/enrollmentplan';
                    // 同分去向
                    if (!userManager.isLogin()) {
                        return;
                    }

                    goPageUrl = '/subpackages/subpackage1/pages/sameDistributionDirection/sameDistributionDirection';
                } else if (index == 8) {
                    if (userManager.isLogin()) {
                        if (getApp().globalData.userInfo.pid) {
                            let restime = uni.getStorageSync('isGKB_graduate_time');
                            if (this.isgaokao == 1 && getApp().globalData.userInfo.graduate_time != restime) {
                                this.gaokaoshow = true;
                                return;
                            }
                            goPageUrl = '/subpackages/subpackage1/pages/chancePage/chancePage';
                        } else {
                            goPageUrl = '/subpackages/subpackage2/pages/login/perfect-info';
                        }
                    }
                    // goPageUrl = '/subpackages/subpackage2/pages/login/perfect-info'
                }

                uni.navigateTo({
                    url: goPageUrl
                });
            }
        },

        // 点击标题
        // tabsChangeTap(e) {
        // 	let index = e.target.dataset.current || e.currentTarget.dataset.current;
        // 	this.currentIndex = index;
        // },

        // 点击志愿表
        // onClickVolunteer() {
        // 	uni.navigateTo({
        // 		url: '/pages/volunteer/volunteer-list'
        // 	})
        // },
        // 点击banner选项卡
        onClickBannerItem(index) {
            if (uni.getStorageSync('is_visitor') == 1 && [3, 4].includes(index)) {
                uni.navigateTo({
                    url: '/pages/login/login-home'
                });
            } else {
                if (index == 0) {
                    // 交流群
                    request.getWeChatURLScheme().then((res) => {
                        const url = res.data.url;
                        if (url != undefined && url.length > 5) {
                            wx.navigateTo(url);
                            // plus.runtime.openURL(url);
                        }
                    });
                } else if (index == 1) {
                    // VIP
                    if (userManager.isLogin()) {
                        uni.navigateTo({
                            url: '/subpackages/subpackage1/pages/midTabBar/midTabBar'
                        });
                    }
                } else if (index == 3) {
                    // 报考推荐
                    if (userManager.isLogin()) {
                        uni.navigateTo({
                            url: '/subpackages/subpackage1/pages/recommend/recommend'
                        });
                    }
                } else if (index == 4) {
                    if (this.xcxName == '报考管家') {
                        wx.navigateToMiniProgram({
                            appId: 'wx5cae3833260cda9f', // 目标小程序的appId
                            path: 'pages/homePage/main?channel=9fa29792bed1484e ', // 目标小程序的页面路径，选填
                            extraData: {
                                // 需要传递给目标小程序的数据，选填
                                // channel: '9fa29792bed1484e'
                            },
                            success(res) {
                                console.log('appId', 'wx5cae3833260cda9f');
                                console.log('path', 'pages/homePage/main');
                                console.log('携带参数', {
                                    channel: '9fa29792bed1484e'
                                });
                                console.log('跳转成功', res);
                                // 打开成功的回调，选填
                            },
                            fail(err) {
                                console.log('跳转失败', err);
                                // 打开失败的回调，选填
                            }
                        });
                    } else {
                        // 测评
                        uni.switchTab({
                            url: '../ping/ping'
                        });
                    }
                } else if (index == 5) {
                    // 商品服务 新增页面
                    if (userManager.isLogin()) {
                        uni.navigateTo({
                            // url: '/subpackages/subpackage1/pages/commodityService/commodityService'
                            url: '/subpackages/subpackage1/pages/zhuan/zhuan'
                        });
                    }
                } else {
                    //邀请
                    if (!userManager.isLogin()) {
                        return;
                    }

                    uni.navigateTo({
                        url: '/pages/tabBar/wode/yaoqingWeb'
                    });
                    // 评测
                    // uni.switchTab({
                    // 	url: '/pages/tabBar/ping/ping'
                    // })
                }
            }
        },
        //swiper change时触发
        // onSwiperChange(e) {
        // 	let index = e.target.current || e.detail.current;
        // 	this.currentIndex = index;
        // },

        //swiper滑动中
        onSwiperTransition(e) {},
        //swiper滑动结束
        onSwiperAnimationfinish(e) {
            let index = e.target.current || e.detail.current;
            this.currentIndex = index;
        },
        onPageScroll(e) {
            const scrollTop = e.detail.scrollTop;
            // const scrollTop = e.detail.scrollTop
            if (scrollTop > 0) {
                // 导航条颜色透明渐变
                if (scrollTop <= 100) {
                    const num = scrollTop / 100;
                    this.opacityNum = 'rgba(255, 255, 255,' + num + ')';
                    this.fontColor = false;
                } else if (scrollTop > 100) {
                    this.opacityNum = 'rgba(255, 255, 255, 1.0)';
                    this.fontColor = true;
                }
            } else {
                this.opacityNum = 'rgba(255, 68, 26, 0)';
            }
        },
        onClickOpenTrialVip() {
            this.productId = 'vip.volunteercard.trial';
            this.sendPayment();
        },

        onClickOpenVolunteerVip() {
            this.productId = 'vip.volunteercard.98';
            this.sendPayment();
        },

        // 点击购买体验卡
        async sendPayment() {
            if (this.environment == 'android') {
                let that = this;
                wx.showLoading({
                    title: '加载中...'
                });
                wx.login({
                    success: (res) => {
                        let userCode = res.code;
                        // 将code传递给服务器
                        this.$request
                            .getWeChatAccessTokenXcx({
                                code: userCode
                            })
                            .then((res) => {
                                if (res.code == 20000) {
                                    this.openid = res.data.openid;
                                    this.fetchCreatWeChatOrderAPI();
                                }

                                // this.wxPlay = res.data
                            });
                    }
                });
                // // 发起微信支付
                // appPay.wxPay({
                // 		card_type: this.productId == 'vip.volunteercard.98' ? 4 : 3
                // 	})
                // 	.then(resData => {
                // 		let {
                // 			res,
                // 			orderInfo
                // 		} = resData

                // 		that.$request.verifyWXPay({
                // 			out_trade_no: orderInfo
                // 		}).then(res => {
                // 			console.log('验证微信支付返回数据', res)
                // 			that.endVipTrialPopup()
                // 			let visitor = uni.getStorageSync('visitorId') || {}
                // 			if (visitor.visitorId) {
                // 				visitor.buy = 1
                // 				api.invitedNew(visitor).then(res => {
                // 					console.log(res);
                // 				})
                // 			}

                // 			that.userInfo = getApp().globalData.userInfo
                // 		})
                // 	})
                // 	.catch(err => {
                // 		console.log('支付失败操作', err)
                // 	})
            } else {
                uni.showToast({
                    title: '当前ios设备不支持',
                    icon: 'none'
                });
                return;
            }
        },
        fetchCreatWeChatOrderAPI() {
            let reqObj = {
                openid: this.openid,
                transactions: 'xcx'
            };
            this.$request.creatWeChatOrderAPI(reqObj).then((res) => {
                if (res.code == 20000) {
                    this.wxPlayData = res.data;
                    wx.hideLoading();
                    // 拿到参数调用微信支付接口
                    wx.requestPayment({
                        timeStamp: res.data.timeStamp + '',
                        nonceStr: res.data.nonceStr,
                        package: res.data.package,
                        signType: 'MD5',
                        paySign: res.data.paySign,
                        success(res) {
                            let visitor = uni.getStorageSync('visitorId') || {};
                            if (visitor.visitorId) {
                                visitor.buy = 1;
                                this.$request.invitedNew(visitor).then((res) => {});
                            }
                            this.userInfo = getApp().globalData.userInfo;
                            wx.showToast({
                                title: '支付成功',
                                icon: 'success',
                                duration: 1000
                            });
                        },
                        fail(res) {
                            wx.showToast({
                                title: '取消支付',
                                icon: 'none',
                                duration: 1000
                            });
                        }
                    });
                    this.opens = false;
                    this.openVipCoupon = false;
                    uni.showTabBar();
                }
            });
        }
    }
};
</script>

<style lang="less" scoped>
.nvue-container {
    overflow: hidden !important;
}

/* 隐藏滚动条 */
.nvue-container::-webkit-scrollbar {
    display: none !important;
}

/* 可选：定制滚动条的样式 */
.nvue-container::-webkit-scrollbar-track {
    background-color: transparent !important;
}

.nvue-container::-webkit-scrollbar-thumb {
    background-color: transparent !important;
}

.popup-center-isGKB {
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.6);
    position: fixed;
    top: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    overflow: hidden;

    .popup-center-box-isGKB {
        width: 100%;
        height: 80%;
        position: fixed;
        top: 8vh;
        display: flex;
        flex-direction: column;
        justify-content: center;
        text-align: center;
        // left: 5%;
        background-image: url('https://mcdn.chatgk.com/xcx/static/images/home/home-isGKB.png');
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;

        .top-title-isGKB {
            position: fixed;
            top: 18vh;
            left: 0%;
            width: 100%;
            display: flex;
            flex-direction: column;
            justify-content: space-around;
            align-items: center;
            text-align: center;
            font-size: 48rpx;
            font-family: PingFangSC, PingFang SC;
            font-weight: bold;
            color: #f8f8f8;

            .center-top {
                display: inline-block;
            }
        }

        .countent {
            position: absolute;
            width: 53vw;
            top: 42vh;
            left: 17%;
            font-size: 26rpx;
            display: flex;
            flex-direction: column;
            justify-content: flex-start;
            align-items: flex-start;
            background-color: #fffaee;
            padding: 24rpx 44rpx;
            border-radius: 16rpx;

            .txt {
                height: 52rpx;
                line-height: 52rpx;
            }
        }

        .button {
            position: absolute;
            width: 60%;
            top: 69vh;
            left: 20%;
            height: 80rpx;
            line-height: 80rpx;
            border-radius: 48rpx;
            text-align: center;
            align-items: center;
            background: #ff3b0a;

            .txt {
                color: #ffffff;
                font-weight: bold;
            }
        }

        .close-isGKB {
            position: fixed;
            top: 91vh;
            left: 46%;
            z-index: 200;
            width: 60rpx;
            height: 60rpx;
        }
    }

    .p-c-b-bottom-isGKB {
        .close-isGKB {
            position: fixed;
            bottom: -200rpx;
            width: 60rpx;
            height: 60rpx;
        }
    }
}

.home {
    /* flex: 1; */
    background-color: #f8f8f8;
}

/* bottom */
.home-bottom {
    padding: 26rpx 0rpx 0rpx 0rpx;
}

/* title */
.home-bottom-tab {
    display: flex;
    flex-direction: row;
    padding: 42rpx 32rpx 20rpx;
    height: 44rpx;
    justify-content: space-between;
    align-items: center;
    background-color: #f8f8f8;
}

.home-bottom-tab-item-title {
    color: #999999;
    font-size: 28rpx;
    line-height: 32rpx;
    margin-right: 28rpx;
    margin-bottom: 10rpx;
}

.home-bottom-tab-item-title-active {
    color: #333333;
    font-size: 32rpx;
    line-height: 40rpx;
    font-weight: bold;
}

.home_news_more_box {
    justify-content: space-between;
    align-items: center;
}

.home_news_more_text {
    color: #999999;
    font-size: 28rpx;
    font-weight: bold;
}

/* pages */
.home-bottom-swiper-view,
.home-bottom-swiper-item {
    flex: 1;
}

.home-bottom-page-item {
    display: flex;
    flex-direction: row;
    align-items: center;
    /* height: 168rpx; */
    padding: 10rpx 32rpx;
    box-sizing: border-box;
    /* align-items: center; */
    /* justify-content: flex-start; */
    background-color: #f8f8f8;
}

.home-bottom-page-item-sub {
    flex: 1;
    padding: 20rpx 26rpx;
    border-radius: 10rpx;
    display: flex;
    flex-direction: row;
    align-items: center;
    background-color: #fff;
}

.home-bottom-page-title {
    /* margin-top: 28rpx; */
    /* height: 40rpx; */
    font-size: 28rpx;
    color: #333333;
    font-weight: bold;
    /* lines: 1; */
    /* text-overflow: ellipsis; */
}

.home-bottom-page-time {
    font-size: 22rpx;
    color: #999999;
}

.home-bottom-page-image {
    width: 184rpx;
    height: 120rpx;
    margin-left: 20rpx;
    border-radius: 10rpx;
}

.home-bottom-page-watch {
    margin-left: 8rpx;
    font-size: 24rpx;
    color: #999999;
}

.home-center {
    margin-top: -20rpx;
}

.home-center-1 {
    margin-top: -80rpx;
}

.view-banner {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    margin: 24rpx 32rpx;
}

.banner-image {
    width: 220rpx;
    height: 140rpx;
}

.fiexdGengxing {
    position: fixed;
    top: 0;
    width: 750rpx;
    height: 100vh;
    z-index: 100000000;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.4);
}

.contentBox {
    width: 600rpx;
    height: 588rpx;
    background: #ffffff;
    border-radius: 20rpx;
    /* margin-top: 500rpx; */
}

.contentBox .gxheader {
    width: 600rpx;
    height: 80rpx;
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    align-items: center;
    padding-right: 30rpx;

    box-sizing: border-box;
}

.contentBox .gxheaderT {
    width: 600rpx;
    display: flex;
    flex-direction: row;
    justify-content: center;
}

.gxheaderText {
    font-size: 36rpx;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
}

.gxheaderTexts {
    font-size: 30rpx;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 400;
    color: #999999;
}

.gxbutton {
    width: 600rpx;
    height: 120rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 30rpx;
}

.gxbuttonC {
    width: 506rpx;
    height: 88rpx;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999;
}

.tiyanxinxian {
    font-size: 36rpx;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #ffffff;
}

.gximage {
    position: absolute;
    width: 506rpx;
    height: 88rpx;
    z-index: -1;
}

.popup-center {
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.6);
    position: fixed;
    top: 0;
    z-index: 999;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;

    .popup-center-box {
        margin: auto;
        width: 90%;
        // height: 1100rpx;

        .p-c-b-top {
            width: 100%;
            height: 70%;
            padding: 40rpx;
            font-size: 26rpx;
            line-height: 40rpx;
            box-sizing: border-box;
            border-radius: 20rpx;
            position: relative;
            background-color: #fff;

            .tuijian {
                position: absolute;
                top: 0;
                left: 0;
                width: 120rpx;
                height: 120rpx;
            }

            .close {
                position: absolute;
                top: 10rpx;
                right: 10rpx;
            }

            .top-title {
                width: 100%;
                display: flex;
                justify-content: center;
                font-size: 38rpx;
                font-weight: 500;
                margin-bottom: 20rpx;
                color: #ff4011;
            }

            .maney {
                width: 100%;
                display: flex;
                flex-direction: row;
                justify-content: center;
                margin-top: 30rpx;
                font-size: 50rpx;
                color: #ff4011;

                .yuan {
                    margin-top: 30rpx;
                    width: 30rpx;
                    height: 30rpx;
                }
            }

            .validity {
                width: 100%;
                display: flex;
                flex-direction: row;
                justify-content: center;
                color: #cacaca;
                font-size: 28rpx;
                margin-top: 10rpx;
            }

            .top-content {
                background-color: #fff;
                border-radius: 20rpx;
                padding: 30rpx 10rpx 0 10rpx;

                view {
                    margin: 10rpx 0 0 0;
                }
            }

            .p-c-b-top-button {
                width: 600rpx;
                color: #ffdaa7;
                margin: 50rpx 0 0 0;
                font-size: 32rpx;
                font-weight: bold;
                text-align: center;
                border-radius: 46rpx;
                height: 92rpx;
                line-height: 92rpx;
                background: #ff3b0a;
                box-shadow: -6rpx 6rpx 10rpx rgba(0, 0, 0, 0.15);
            }
        }
    }
}

/* .home-bottom-swiper-item-content */
</style>
